package com.bruce.pattern.behavioral.iterator;

import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * Created by bruce on 2018/11/10 13:30
 */
@Slf4j
public class CourseIteratorImpl<E> implements CourseIterator<E> {

    private List<E> list;

    private int position;

    CourseIteratorImpl(List<E> list) {
        this.list = list;
    }

    @Override
    public E next() {
        log.info("返回课程,位置是:" + position);
        E item = list.get(position);
        position++;
        return item;
    }

    @Override
    public boolean hasNext() {
        return list != null && position < list.size();
    }
}
